// packagBuy/pages/found/index/index.js
var util = require('../../../../utils/util')   //引入配置公共请求接口
import { foundApi,getCarNumber } from '../../../../config/config'
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    footprintGuid: '', //足迹全局id
    isShowPartnerAll:true,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    templateList: [],
    recommendList: [],
    toCrmParams:'',
    carGoods:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getSystemInfo({
      success (res) {
        let statusBarHeight = res.statusBarHeight
        console.log(statusBarHeight)
        that.setData({
          titleHeight: statusBarHeight + 'px'
        })
      }
    })
    that.getRecommendList()
    that.getCarGoodsNumber()
    that.setData({
      toCrmParams: JSON.stringify({ url: '/pages/home/main/index'})
    })
  },
   // 展示合伙人二维码
   partnerCode: function(e) {
    const codeImg = e.target.dataset.url
    wx.previewImage({
      urls: [codeImg],
      current: codeImg // 当前显示图片的http链接
    })
    
  },
  // 关闭合伙人二维码
  closeCodePop: function() {
    this.setData({
      showPartnerCodePop: false
    })
  },
   // 展开合伙人信息
   showPartnerAll: function() {
    this.setData({
      isShowPartnerAll:!this.data.isShowPartnerAll
    })
  },
// 获取推荐
getRecommendList() {
  let that = this
  const param = {
    rows: 10
  }
  app.reqFun.requestJson('GET',foundApi.getRecommendList,param,(res)=>{
    if(res.data.success==1){
      this.setData({
        recommendList: res.data.data
      })
      console.log('recommendList', that.data.recommendList)
    }
  }) 
},
getCarGoodsNumber() { //查询购物车商品数-
  var that = this;
  app.reqFun.requestJson('POST', getCarNumber, '', (res) => {
    if (res.data.success == 1) {
      that.setData({
        carGoods: res.data.data
      })
    }
  }, true)
},
  goEncyclopedia() {
    wx.navigateTo({
      url: '/packagBuy/pages/found/encyclopedia/encyclopedia',
    })
  },
  goShow() {
    wx.navigateTo({
      url: '/packagBuy/pages/found/show/show',
    })
  },
  goMeita() {
    wx.navigateToMiniProgram({
      appId: 'wx0115d6a0eef80e3a',//小程序appid
      path: 'pages/home/main/index',//跳转关联小程序app.json配置里面的地址
      extraData: {
        foo: 'bar'
      },
     //**重点**要打开的小程序版本，有效值 develop（开发版），trial（体验版），release（正式版） 
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let that = this
    let query = wx.createSelectorQuery();
    query.select('.found_top').boundingClientRect(rect=>{
      let clientHeight = rect.height;
      // let clientWidth = rect.width;
      // let ratio = 750 / clientWidth;
      // let height = clientHeight * ratio;
      that.setData({
        topHeight: clientHeight
      })
    }).exec();
  },
  goreBack: function (e) { //返回
    wx.navigateBack({
      delta: 1
    })
  },
  goHome: function (e) { //返回主页
    wx.reLaunch({
      url: '/pages/newIndex/newIndex'
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      footprintGuid: util.guid()
    })
    setTimeout(()=>{
      this.setData({
        partnerInfo:getApp().globalData.partnerInfo
      })
      },500)
    //保存访问足迹
    app.saveAccessFootprint(this.data.footprintGuid, 'uFound', null)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    //保存退出足迹
    app.saveQuitFootprint(this.data.footprintGuid)
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    //保存退出足迹
    app.saveQuitFootprint(this.data.footprintGuid)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }

  //登录-注册
  bindGetUserInfo: function (e) {
    app.getUserInfo()
    this.setData({
      showSetting: false,
      isShowGetUserInfo: false
    })
  },
  //登录弹窗关闭回调
  onCloseShowGetUserInfo() {
    this.setData({
      showSetting: false,
      isShowGetUserInfo: false
    })
  },
})